package com.neuedu.javase.io;

import java.io.*;

/***
 * 项目名称:  MyJavaSE 
 * 包：  com.neuedu.javase.io 
 * date:   2025/11/5   16:41  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class MyIoStream {

    public static void main(String[] args) {
        String dir = "d:\\upload";
        String src   = "b.txt";
        String dist  = "c.txt";


        //使用InputStream 读取文件
        InputStream is = null;
        OutputStream os = null;

        try {
            is = new FileInputStream(new File(dir,src));
            os = new FileOutputStream(new File(dir,dist));

            byte[] buffer = new byte[1024];
            int len  = 0;
            // System.out.print(new String(buffer));
            while((len = is.read(buffer)) != -1){
                // os.write(buffer);
                os.write(buffer, 0, len);
                os.flush();
            }


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        finally {
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(os != null){
                try {
                    os.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }



    }
}
